package com.ruoyi.chat.service.impl;

import java.util.List;

import com.ruoyi.chat.domain.ChatUser;
import com.ruoyi.chat.domain.GroupMessage;
import com.ruoyi.common.core.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.chat.mapper.ChatGroupMapper;
import com.ruoyi.chat.domain.ChatGroup;
import com.ruoyi.chat.service.IChatGroupService;

/**
 * 群Service业务层处理
 *

 * @date 2023-07-23
 */
@Service
public class ChatGroupServiceImpl implements IChatGroupService
{
    @Autowired
    private ChatGroupMapper chatGroupMapper;

    /**
     * 查询群
     *
     * @param groupId 群主键
     * @return 群
     */
    @Override
    public ChatGroup selectChatGroupByGroupId(Long groupId)
    {
        return chatGroupMapper.selectChatGroupByGroupId(groupId);
    }

    /**
     * 查询群列表
     *
     * @param chatGroup 群
     * @return 群
     */
    @Override
    public List<ChatGroup> selectChatGroupList(ChatGroup chatGroup)
    {
        return chatGroupMapper.selectChatGroupList(chatGroup);
    }

    /**
     * 新增群
     *
     * @param chatGroup 群
     * @return 结果
     */
    @Override
    public int insertChatGroup(ChatGroup chatGroup)
    {
        chatGroup.setCreateTime(DateUtils.getNowDate());
        return chatGroupMapper.insertChatGroup(chatGroup);
    }

    /**
     * 修改群
     *
     * @param chatGroup 群
     * @return 结果
     */
    @Override
    public int updateChatGroup(ChatGroup chatGroup)
    {
        chatGroup.setUpdateTime(DateUtils.getNowDate());
        return chatGroupMapper.updateChatGroup(chatGroup);
    }

    /**
     * 批量删除群
     *
     * @param groupIds 需要删除的群主键
     * @return 结果
     */
    @Override
    public int deleteChatGroupByGroupIds(Long[] groupIds)
    {
        return chatGroupMapper.deleteChatGroupByGroupIds(groupIds);
    }

    /**
     * 删除群信息
     *
     * @param groupId 群主键
     * @return 结果
     */
    @Override
    public int deleteChatGroupByGroupId(Long groupId)
    {
        return chatGroupMapper.deleteChatGroupByGroupId(groupId);
    }


    /**
     * 删除群信息
     *
     * @param groupId 群主键
     * @return 结果
     */
    @Override
    public List<ChatUser> selectChatGroupUserById(Long groupId) {
        return chatGroupMapper.selectChatGroupUserByGroupId(groupId);
    }

    @Override
    public List<ChatGroup> AllGroupLastOne(Long userId) {
        List<ChatGroup> chatGroups=chatGroupMapper.selectChatGroupByUserId(userId);
        System.out.println("11111");
        System.out.println(chatGroups);
        return chatGroups;
    }

    @Override
    public List<GroupMessage> AllGroupMessageLastOne(Long groupId,Integer num) {
        chatGroupMapper.selectAllGroupMessage(groupId,num);
        return null;
    }

    @Override
    public List<ChatUser> selectChatGroupUserByGroupId(Long groupId) {
        return chatGroupMapper.selectChatGroupUser(groupId);
    }

    /**
     * 获取商家信息
     */
//    @Override
//    public ChatGroup selectChatGroupByBusinessId(Long businessId) {
//        return chatGroupMapper.selectChatGroupByBusinessId(businessId);
//    }
}
